"""
Django settings for jfpal project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os, sys
import pytz
from settings_local import *
from django.utils import timezone

BASE_DIR = os.path.dirname(__file__)


TIME_ZONE = 'Asia/Shanghai'

GEOIP_DATABASE = '%s/data/GeoLiteCity.dat' % BASE_DIR


STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # + "/media/"
#MEDIA_URL = '%s/media/' % HOSTNAME

STATIC_PATH= os.path.join(os.path.dirname(__file__), 'media').replace('\\','/')


STATICFILES_DIRS = (
  os.path.join(BASE_DIR, 'static2'),
)

#print STATICFILES_DIRS, BASE_DIR

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '(a4dr_1&4!7%4j%dj#-*bz=v)(+6#&fgs=#c0huy%io(svh2im'

# SECURITY WARNING: don't run with debug turned on in production!

TEMPLATE_DEBUG = DEBUG

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.flatpages',
    'api',
    
    'rest_framework',
    'store',
    'sdk',
    'customer',
    'module',
    'feedback',
    'adminsortable',
    'ckeditor',
    'django_wysiwyg',
    'easy_timezones',
)

INSTALLED_APPS += ( 'flagship', )

INSTALLED_APPS += (
	'gunicorn',
)


INSTALLED_APPS += (
    'imagekit',
)


INSTALLED_APPS += (
                   'south',
                   )

#see https://github.com/jrief/django-admin-sortable2
INSTALLED_APPS += (
                   'adminsortable',
                   )

#see https://github.com/dyve/django-bootstrap3
INSTALLED_APPS += (
                   'bootstrap3',
                   )

#sudo pip install -e git://github.com/thenewguy/django-faq.git#egg=django_faq
INSTALLED_APPS += (
                   'faq',
                   )


BOOTSTRAP3 = {
    'jquery_url': '%srest_framework/js/jquery-1.8.1-min.js' % STATIC_URL,
    'base_url': 'http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/',
    'css_url': None,
    'theme_url': None,
    'javascript_url': None,
    'horizontal_label_class': 'col-md-2',
    'horizontal_field_class': 'col-md-4',
}

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'templates') # + "/media/"
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    #'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'api.middlewares.ThreadLocal.ThreadLocalMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
    'easy_timezones.middleware.EasyTimezoneMiddleware',
)

ROOT_URLCONF = 'urls'

WSGI_APPLICATION = 'wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases



# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
from django.utils.translation import ugettext_lazy as _

_ = lambda s: s

LANGUAGES = (
    ('zh', _('zhongguo')),
    ('en', _('English')),
)

LANGUAGE_CODE = 'zh-cn'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/


#rest framework setting
REST_FRAMEWORK = {
    # Use hyperlinked styles by default.
    # Only used if the `serializer_class` attribute is not set on a view.
    'DEFAULT_MODEL_SERIALIZER_CLASS':
        'rest_framework.serializers.HyperlinkedModelSerializer',

    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ]
}


TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader',
 'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader'
)


LOCALE_PATHS = (
    #'/home/www/project/common_files/locale',
    #'/var/local/translations/locale'
)

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'console': {
            'level': 'INFO',
            'filters': ['require_debug_false'],
            'class': 'logging.StreamHandler',
            'stream': sys.stdout,
            'formatter': 'simple',
        },
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'app.location': {
            'handlers': ['console'],
            'level': 'INFO',
            'propagate': False,
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

DJANGO_WYSIWYG_FLAVOR = "ckeditor"
CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_IMAGE_BACKEND = "pillow"
